package net.huashitong.user.web;

import java.util.ArrayList;
import java.util.List;

import net.huashitong.user.databean.DynamicDatabean;
import net.huashitong.user.entity.Dynamic;
import net.huashitong.user.filter.DynamicFilter;
import net.huashitong.user.service.DynamicService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;

/**
 * 消息动态
 * @author lzr
 *
 */
@Controller
@RequestMapping("/app/dynamic")
public class DynamicController extends JsonBaseController {

	@Autowired
	private DynamicService dynamicService;
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * 保存消息动态
	 * @param dynamicFilter
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/saveDynamic")
	public Message saveDynamic(@RequestBody DynamicFilter dynamicFilter){
		
		Dynamic dynamic = new Dynamic();
		dynamic.setUserId(dynamicFilter.getUserId());
		dynamic.setPhotoId(dynamicFilter.getPhotoId());
		dynamic.setText(dynamicFilter.getText());
		dynamic.setDate(dynamicFilter.getDate());
		dynamicService.save(dynamic);
		return coverMessage("200", "保存成功");
	}
	/**
	 * 查询消息动态
	 * @return
	 */
	@RequestMapping("/queryDynamic")
	@ResponseBody
	public Message queryDynamic(){
		List<Dynamic> dynamics = dynamicService.queryOrderDate();
		List<DynamicDatabean> databeans = new ArrayList<DynamicDatabean>();
		for (Dynamic dynamic : dynamics) {
			DynamicDatabean databean = new DynamicDatabean();
			databean.setDate(dynamic.getDate());
			databean.setPhotoId(dynamic.getPhotoId());
			databean.setText(dynamic.getText());
			databean.setSysId(dynamic.getSysId());
			databeans.add(databean);
		}
		return coverMessage("200", "数据获取成功",databeans);
	}
	
	
	@RequestMapping("/delDynamic")
	@ResponseBody
	public Message delDynamic(@RequestBody DynamicFilter dynamicFilter){
		dynamicService.deleteById(dynamicFilter.getSysId());
		return coverMessage("200", "数据删除成功");
	}
}
